 //114.二叉树展开为链表
 //https://leetcode.cn/problems/flatten-binary-tree-to-linked-list/?envType=study-plan-v2&envId=top-100-liked
class Solution {
    TreeNode* prev = nullptr;
public:
    void flatten(TreeNode* root) {
        //后序遍历 先遍历右边 再遍历左边 在离开当前节点前 记录节点 并将当前节点指向上一个节点
        if(!root) return;
        TreeNode* l = root->left;
        root->left = nullptr;
        flatten(root->right);
        flatten(l);
        root->right = prev;
        prev = root;
    }
};